"""
Basic example showing how to schedule a callable using a textual reference.
"""

import os

# 引入同步调度类
from apscheduler.schedulers.blocking import BlockingScheduler


# def task(name, info):
#     print(f"醒醒啦 {name}  {info}")
#
# if __name__ == "__main__":
#     # 构建调度实例
#     scheduler = BlockingScheduler()
#
#     scheduler.add_job("sys:stdout.write", "interval", seconds=3, args=["tick\n"])
#
#     scheduler.add_job(task, "interval", seconds=3, args=("小马同学", "开饭啦"))
#
#
#     try:
#         # 启动调度
#         scheduler.start()
#     except (KeyboardInterrupt, SystemExit):
#         pass




"""
Demonstrates how to schedule a job to be run in a process pool on 3 second intervals.
"""

import os
from datetime import datetime

from apscheduler.schedulers.blocking import BlockingScheduler


def tick():
    print(f"Tick! The time is: {datetime.now()}")


if __name__ == "__main__":
    scheduler = BlockingScheduler()
    # 创建进程池
    scheduler.add_executor("processpool")
    scheduler.add_job(tick, "interval", seconds=3)
    print("Press Ctrl+{} to exit".format("Break" if os.name == "nt" else "C"))

    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        pass



"""
Demonstrates how to use the asyncio compatible scheduler to schedule a job that executes on 3
second intervals.
"""

# import asyncio
# import os
# from datetime import datetime
#
# from apscheduler.schedulers.asyncio import AsyncIOScheduler
#
#
# def tick():
#     print(f"Tick! The time is: {datetime.now()}")
#
#
# async def main():
#     scheduler = AsyncIOScheduler()
#     scheduler.add_job(tick, "interval", seconds=3)
#     scheduler.start()
#     print("Press Ctrl+{} to exit".format("Break" if os.name == "nt" else "C"))
#     while True:
#         await asyncio.sleep(1000)
#
#
# if __name__ == "__main__":
#     # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
#     try:
#         asyncio.run(main())
#     except (KeyboardInterrupt, SystemExit):
#         pass



# import asyncio
# import os
# from datetime import datetime,timedelta
#
# from apscheduler.schedulers.asyncio import AsyncIOScheduler
# from apscheduler.triggers.date import DateTrigger
#
# def tick():
#     print(f"Tick! The time is: {datetime.now()}")
#
#
# async def main():
#     scheduler = AsyncIOScheduler()
#
#     # 指定时间运行爬虫
#     scheduler.add_job(tick, DateTrigger(datetime.now() + timedelta(seconds=10)))
#     scheduler.start()
#     print("Press Ctrl+{} to exit".format("Break" if os.name == "nt" else "C"))
#     while True:
#         await asyncio.sleep(1000)
#
#
# if __name__ == "__main__":
#     # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
#     try:
#         asyncio.run(main())
#     except (KeyboardInterrupt, SystemExit):
#         pass